package com.company.service;

import com.company.dao.AccountsDao;
import com.company.entity.Accounts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AccountsService {
    @Autowired
    AccountsDao accountsDao;

    public String query() {
        return accountsDao.findAll().get(0).getUsername();
    }

    public Accounts list() {
        return accountsDao.findAll().get(0);
    }

    public boolean login(String username, String password) {
        Accounts accounts = accountsDao.findAll().get(0);
        return username.equals(accounts.getUsername()) && password.equals(accounts.getPassword());
    }

    public void update(Accounts accounts) {
        Accounts admin = accountsDao.findAll().get(0);
        accounts.setId(admin.getId());
        accountsDao.save(accounts);
    }
}
